package com.djbx.points.member.sharding.algorithms;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * 〈〉
 *
 * @author sader
 * @date 2021/11/29
 * @since 1.0.0
 */
public class MemberDBShardingAlgorithm implements PreciseShardingAlgorithm<Long> {

    /**
     * 分表策略
     * @param availableTargetNames 可用的表名
     * @param shardingValue 当前数据信息
     * @return 对应表名
     */
    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {
        Long id = shardingValue.getValue();
        long suffix = (id % 2);
        return "master" + suffix;
    }
}
